package com.cz.fra.utils;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {

	public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
	
	public static SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
	
	public static Timestamp stringToTimestamp(String s){
		return Timestamp.valueOf(s);
	}
	
	public static String timestampToString(Timestamp t){
		return dateFormat.format(t);
	}
	
	public static Date stringToDate(String s){
		Date d = null;
		try {
			 d = dateFormat.parse(s);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return d;
	}
	
	public static String dateToString(Date t){
		return dateFormat.format(t);
	}
	
	public static boolean compareDate(String s1, String s2){
		boolean firstOneBig = true;
		try {
			Date d1 = dateFormat.parse(s1);
			Date d2 = dateFormat.parse(s2);
			if(d1.getTime() < d2.getTime()){
				firstOneBig = false;
			}
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return firstOneBig;
	}
	
	public static Date sqlDateToDate(java.sql.Date sqlDate){
		return new Date(sqlDate.getTime());
	}
}
